class TaskForm
  def initialize task
    @task = task
		@statusModel = [["0",GLib.locale_to_utf8(_("Fresh"))],["1",GLib.locale_to_utf8(_("Ongoing"))],["2",GLib.locale_to_utf8(_("Delay"))],["3",GLib.locale_to_utf8(_("Discard"))],["4",GLib.locale_to_utf8(_("Complete"))]]

    now = Time.now
    #
    taskNameLabel = Gtk::Label.new GLib.locale_to_utf8(_("Task Name"))
    @taskNameEntry = Gtk::Entry.new
    @taskNameEntry.width_chars = 15
    if @task != nil
      @taskNameEntry.text = @task.name
    end
    
    taskStartTimeLabel = Gtk::Label.new GLib.locale_to_utf8(_("Start Time"))
    @taskStartDateEntry = Gtk::Entry.new
    @taskStartDateEntry.width_chars = 10
    @taskStartTimeCombo = Gtk::ComboBox.new
    @taskStartTimeCombo.wrap_width = 4
    
    taskDeadlineLabel = Gtk::Label.new GLib.locale_to_utf8(_("Deadline"))
    @taskDeadlineEntry = Gtk::Entry.new
    @taskDeadlineEntry.width_chars = 10
    @taskDeadlineTimeCombo = Gtk::ComboBox.new
    @taskDeadlineTimeCombo.wrap_width = 4
    24.times do |i|
      @taskStartTimeCombo.append_text i.to_s
      @taskDeadlineTimeCombo.append_text i.to_s
      if now.strftime("%H").to_i == i
        @taskStartTimeCombo.set_active i
        @taskDeadlineTimeCombo.set_active i
      end
    end
    
    if @task != nil
      stime = @task.startTime.split " "
      @taskStartDateEntry.text = stime[0]
      @taskStartTimeCombo.set_active stime[1].to_i
        
      etime = @task.deadline.split " "
      @taskDeadlineEntry.text = etime[0]
      @taskDeadlineTimeCombo.set_active etime[1].to_i
    else
      @taskStartDateEntry.text = now.strftime("%Y-%m-%d")
      @taskDeadlineEntry.text = now.strftime("%Y-%m-%d")
    end
    
    taskStatusLabel = Gtk::Label.new GLib.locale_to_utf8(_("Status"))
    @taskStatusComboBox = Gtk::ComboBox.new
    @taskStatusComboBox.append_text @statusModel[0][1]
    @taskStatusComboBox.append_text @statusModel[1][1]
    @taskStatusComboBox.append_text @statusModel[2][1]
    @taskStatusComboBox.append_text @statusModel[3][1]
    @taskStatusComboBox.append_text @statusModel[4][1]
    
    if @task != nil
      @taskStatusComboBox.active = @task.status.to_i
    else
      @taskStatusComboBox.active = 0
    end
    
    taskCommentLabel = Gtk::Label.new GLib.locale_to_utf8(_("Comment"))
    @taskCommentView = Gtk::TextView.new
    @taskCommentView.set_size_request(220, 100)
		buffer = @taskCommentView.buffer
		format = buffer.serialize_formats[0]
		buffer.register_serialize_target(nil)
		buffer.register_deserialize_target(nil)
    
    if @task != nil
      @taskCommentView.buffer.text = @task.comment
    end
    
    @taskStartDateEntry.add_events(Gdk::Event::BUTTON_PRESS_MASK)
    @taskStartDateEntry.signal_connect("focus_in_event") do |widget,event|
      dialog = Gtk::Dialog.new(GLib.locale_to_utf8(_("Get your start time")),$main_application_window,Gtk::Dialog::DESTROY_WITH_PARENT,[ Gtk::Stock::OK, Gtk::Dialog::RESPONSE_NONE ])
      calendar = Gtk::Calendar.new
      dialog.vbox.add calendar
      dialog.signal_connect("response"){ 
        @taskStartDateEntry.text = calendar.date.join "-"
        @taskNameEntry.grab_focus
        dialog.destroy 
      }
      dialog.show_all
    end
    
    @taskDeadlineEntry.add_events(Gdk::Event::BUTTON_PRESS_MASK)
    @taskDeadlineEntry.signal_connect("focus_in_event") do |widget,event|
      dialog = Gtk::Dialog.new(GLib.locale_to_utf8(_("Get your deadline")),$main_application_window,Gtk::Dialog::DESTROY_WITH_PARENT,[ Gtk::Stock::OK, Gtk::Dialog::RESPONSE_NONE ])
      calendar = Gtk::Calendar.new
      dialog.vbox.add calendar
      dialog.signal_connect("response"){ 
        @taskDeadlineEntry.text = calendar.date.join "-"
        @taskNameEntry.grab_focus;
        dialog.destroy 
      }
      dialog.show_all
    end
    
    @form = Gtk::Fixed.new
    @form.put taskNameLabel,10,10
    @form.put @taskNameEntry,100,10
    @form.put taskStartTimeLabel,10,40
    @form.put @taskStartDateEntry,100,40
    @form.put @taskStartTimeCombo,200,40
    @form.put taskDeadlineLabel,10,70
    @form.put @taskDeadlineEntry,100,70
    @form.put @taskDeadlineTimeCombo,200,70
    @form.put taskStatusLabel,10,100
    @form.put @taskStatusComboBox,100,100
    @form.put taskCommentLabel,10,130
    @form.put Gtk::ScrolledWindow.new.add(@taskCommentView),10,150
    
    @form.show_all
  end
  
  def getTips
    @taskCommentView.buffer.text
  end
  
  def getForm
    @form
  end
  
  def getCurrentTask
    if @task == nil
      @task = Task.new
      @task.id = UUID.create_random.to_s
    end
    @task.name = @taskNameEntry.text
    @task.startTime = @taskStartDateEntry.text + " " +@taskStartTimeCombo.active_text
    @task.deadline = @taskDeadlineEntry.text + " " +@taskDeadlineTimeCombo.active_text
    @task.status = @taskStatusComboBox.active
    @task.comment = GLib.filename_from_utf8 @taskCommentView.buffer.text
    return @task
  end
  
end